package com.csrcb.controller;

import com.csrcb.entity.User;
import com.csrcb.service.UserService;
import com.csrcb.tool.RequestInfo;
import com.csrcb.tool.Response;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Classname UserController
 * @Date 2021年7月30日10:05:57
 * @Created by gangye
 */
@RestController
@RequestMapping(value = "/api/user")
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/getOneUser")
    public Response getOneUser(@RequestBody User user){
        Response response = Response.newResponse();
        response.setData(userService.getOneUser(user));
        return response;
    }

    @PostMapping("/getAllUser")
    public Response getAllUser(){
        Response response = Response.newResponse();
        response.setData(userService.getUserList());
        return response;
    }

    @PostMapping("/addUser")
    public Response addUser(@RequestBody RequestInfo<Map> requestInfo){
        Response response = Response.newResponse();
        try {
            log.info("请求的报文：{}",new ObjectMapper().writeValueAsString(requestInfo));
        } catch (JsonProcessingException e) {
            log.error("打印报文日志失败...");
        }
        //业务逻辑处理...
        log.info("交易成功");
        return response;
    }
}
